package Frame;
import DataBase.SQL_Readin;
import InterFace.ManWin_api;
import MeHua.NewManPanel;
import MeHua.UBorder;
import MeHua.UFONT;
import com.eltima.components.ui.DatePicker;
import pojo.*;
import javax.swing.*;
import javax.swing.event.MenuEvent;
import javax.swing.event.MenuListener;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.math.BigDecimal;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;

public class ManWin implements ManWin_api {//郭
    String className;
    SQL_Readin db = new SQL_Readin();
    UTable utable = new UTable();
    JLabel number = new JLabel();//显示在右上角的账号登录信息
    JLabel class_id = new JLabel();
    //本窗口
    JLabel tip = new JLabel("请在上方菜单选择功能");
    JFrame BaseWin = new JFrame("管理用户系统");
    JButton b_peo_man = new JButton("人员管理");
    JButton b_inf_man = new JButton("记录管理");
    JMenuBar menuBar = new JMenuBar();
    JMenu peo_menu = new JMenu("人员管理");
    JMenu inf_menu = new JMenu("记录管理");
    JMenuItem m_stu_man = new JMenuItem("班级人员管理");
    JMenuItem m_unit_man = new JMenuItem("班委会人员管理");
    JMenuItem m_duty_man = new JMenuItem("值日安排管理");
    JMenuItem m_money_inf = new JMenuItem("日常消费记录");
    JMenuItem m_action_inf = new JMenuItem("班级活动记录");
    JMenuItem m_RePun_inf = new JMenuItem("奖惩记录");
    JMenuItem m_message_inf = new JMenuItem("留言簿记录");
    //左面板导航栏
    JLabel map_first_man = new JLabel("请在上方菜单选择功能");
    JLabel map_second_peo = new JLabel("=>人员方面管理功能");
    JLabel map_thread_peo = new JLabel(" ");
    JLabel map_second_inf = new JLabel("=>记录方面管理功能");
    JLabel map_thread_inf = new JLabel(" ");
    //次级菜单选择
    JLabel map_next_stu = new JLabel(">班级人员管理");
    JLabel map_next_unit = new JLabel(">班委会管理");
    JLabel map_next_duty = new JLabel(">值日管理");
    JLabel map_next_money = new JLabel(">消费记录管理");
    JLabel map_next_mess = new JLabel(">留言记录管理");
    JLabel map_next_RePun = new JLabel(">奖惩记录管理");
    JLabel map_next_action = new JLabel(">班级活动管理");
    //人员管理选择功能界面
    JPanel peo_panel = new JPanel();
    JButton b_stu_man = new JButton("班级人员管理");
    JButton b_unit_stu_man = new JButton("班委会人员管理");
    JButton b_duty_man = new JButton("值日安排管理");
    //记录管理选择功能界面
    JPanel inf_panel = new JPanel();
    JButton b_money_inf = new JButton("日常费用记录");
    JButton b_action_inf = new JButton("班级活动记录");
    JButton b_RePun_inf = new JButton("奖惩记录");
    JButton b_message_inf = new JButton("班级留言簿");
    //班级人员管理功能
    JLabel l1 = new JLabel("学号");
    JLabel l2 =new JLabel("姓名");
    JLabel l3 = new JLabel("年龄");
    JLabel l4 =new JLabel("性别");
    JLabel l5 =new JLabel("联系方式");
    JLabel l6 =new JLabel("地址");
    JTextField tf1 = new JTextField();
    JTextField tf2 = new JTextField();
    JTextField tf3 = new JTextField();
    JTextField tf4 = new JTextField();
    JTextField tf5 = new JTextField();
    JTextField tf6 = new JTextField();
    NewManPanel stu_panel = new NewManPanel();
    //班委会人员管理功能
    JPanel unit_panel = new JPanel();
    //值日安排管理
    JPanel duty_panel = new JPanel();
    //消费管理
    JLabel la1;
    JLabel la2;
    JLabel la3;
    JLabel la4;
    JLabel la5;
    JTextField ta1;
    JTextField ta2;
    JTextField ta3;
    JTextField ta4;
    JTextField ta5;
    JPanel money_inf_panel = new JPanel();
    //日常消费记录
   //班级活动管理
    JPanel action_panel=new JPanel();
    JPanel message_panel=new JPanel();

    //奖惩记录
    JPanel RePun_panel=new JPanel();

    public ManWin(String number,String id){//郭
        this.number.setText("管理用户： "+number);
        this.class_id.setText("班级:  "+id);
        this.className = id;
    }
    public void creat(){//郭
        BaseWin.add(tip);
        tip.setBounds(20,50,200,50);
        BaseWin.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        BaseWin.setLayout(null);
        BaseWin.setBounds(400,100,1000,700);
        number.setBounds(850,0,150,50);
        BaseWin.add(number);
        number.setFont(UFONT.getFont3());
        class_id.setBounds(750,0,150,50);
        BaseWin.add(class_id);
        class_id.setFont(UFONT.getFont3());
        number.setForeground(new Color(95,95,95));
        class_id.setForeground(new Color(95,95,95));
        BaseWin.setResizable(false);
        //b_peo_man.setBounds(50,10,100,60);
        //b_inf_man.setBounds(300,10,100,60);
        BaseWin.add(peo_panel);
        peo_panel.setBounds(10,100,200,600);
        peo_panel.setBackground(new Color(255 ,250 ,240));
        BaseWin.add(b_peo_man);
        BaseWin.add(b_inf_man);
        peo_menu.add(m_stu_man);
        peo_menu.add(m_unit_man);
        peo_menu.add(m_duty_man);
        inf_menu.add(m_money_inf);
        inf_menu.add(m_action_inf);
        inf_menu.add(m_RePun_inf);
        inf_menu.add(m_message_inf);
        menuBar.setPreferredSize(new Dimension(1000,50));
        menuBar.add(peo_menu);
        menuBar.add(inf_menu);
        BaseWin.setJMenuBar(menuBar);
        map_first_man.setFont(UFONT.getFont3());
        map_second_peo.setFont(UFONT.getFont3());
        map_thread_peo.setFont(UFONT.getFont3());
        map_second_inf.setFont(UFONT.getFont3());
        map_thread_inf.setFont(UFONT.getFont3());
        map_second_inf.setForeground(new Color(58,95,205));
        map_second_peo.setForeground(new Color(58,95,205));
        BaseWin.add(stu_panel);
        stu_panel.setBounds(210,100,800,600);
        BaseWin.setVisible(true);
        //按钮打开人员管理选择界面，左边面板
        peo_menu.addMenuListener(new MenuListener() {
            public void menuSelected(MenuEvent e) {
                BaseWin.remove(inf_panel);
                BaseWin.remove(peo_panel);
                fun_peo_panel();
            }
            @Override
            public void menuDeselected(MenuEvent e) {
            }
            @Override
            public void menuCanceled(MenuEvent e) {
            }
        });
        //按钮打开记录管理选择界面，右边主要面板
        inf_menu.addMenuListener(new MenuListener(){
            @Override
            public void menuSelected(MenuEvent e) {
                BaseWin.remove(inf_panel);
                BaseWin.remove(peo_panel);
                fun_inf_panel();
            }
            @Override
            public void menuDeselected(MenuEvent e) {
            }
            @Override
            public void menuCanceled(MenuEvent e) {
            }
        });
    }

    public void fun_peo_panel(){//郭
        peo_panel=flush();
        BaseWin.add(peo_panel);
        BaseWin.repaint();
        peo_panel.setLayout(null);
        peo_panel.setBounds(10,100,200,600);
        //b_stu_man.setBounds(0,10,100,60);
        peo_panel.setBackground(new Color(255 ,250 ,240));
        peo_panel.add(b_stu_man);
        //b_unit_stu_man.setBounds(0,100,100,60);
        peo_panel.add(b_unit_stu_man);
        //b_duty_man.setBounds(0,200,100,60);
        peo_panel.add(b_duty_man);
        peo_panel.add(map_first_man);
        map_first_man.setBounds(10,50,150,30);
        peo_panel.add(map_second_peo);
        map_second_peo.setBounds(40,100,150,30);
        peo_panel.add(map_thread_peo);
        map_thread_peo.setBounds(70,150,150,30);
        //次级；
        map_second_peo.setBorder(UBorder.getBorder1());
        map_next_stu.setBorder(UBorder.getBorder1());
        map_next_unit.setBorder(UBorder.getBorder1());
        map_next_duty.setBorder(UBorder.getBorder1());
        map_next_stu.setBounds(70,150,150,30);
        map_next_unit.setBounds(70,190,150,30);
        map_next_duty.setBounds(70,230,150,30);
        map_next_stu.setForeground(new Color(58,95,205));
        map_next_unit.setForeground(new Color(58,95,205));
        map_next_duty.setForeground(new Color(58,95,205));
        //次级导航选择
        map_second_peo.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                peo_panel.add(map_next_stu);
                peo_panel.add(map_next_unit);
                peo_panel.add(map_next_duty);
                peo_panel.remove(map_thread_peo);
                peo_panel.repaint();
            }
        });
        map_next_stu.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                fun_stu_panel();
            }
        });
        map_next_unit.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                fun_unit_panel();
            }
        });
        map_next_duty.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                fun_duty_panel();
            }
        });
        //菜单导航选择
        m_stu_man.addActionListener(e -> {
            fun_stu_panel();
            map_thread_peo.setText("==>班级人员管理");
            peo_panel.add(map_thread_peo);
        });
        m_unit_man.addActionListener(e -> {
            fun_unit_panel();
            map_thread_peo.setText("==>班委会人员管理");
            peo_panel.add(map_thread_peo);
        });
        m_duty_man.addActionListener(e -> {
            fun_duty_panel();
            map_thread_peo.setText("==>值日人员管理");
            peo_panel.add(map_thread_peo);
        });
    }
    public void fun_inf_panel(){//郭
        inf_panel=flush();
        BaseWin.add(inf_panel);
        BaseWin.repaint();
        inf_panel.setLayout(null);
        inf_panel.setBounds(10,100,200,600);
        inf_panel.setBackground(new Color(255 ,250 ,240));
        //b_money_inf.setBounds(0,10,100,60);
        //b_action_inf.setBounds(0,100,100,60);
        //b_RePun_inf.setBounds(0,200,100,60);
        //b_message_inf.setBounds(0,300,100,60);
        inf_panel.add(map_first_man);
        map_first_man.setBounds(10,50,150,30);
        inf_panel.add(map_second_inf);
        map_second_inf.setBounds(40,100,150,30);
        inf_panel.add(map_thread_inf);
        map_thread_inf.setBounds(70,150,150,30);
        inf_panel.add(b_money_inf);
        inf_panel.add(b_action_inf);
        inf_panel.add(b_RePun_inf);
        inf_panel.add(b_message_inf);
        //
        map_second_inf.setBorder(UBorder.getBorder1());
        map_next_money.setBorder(UBorder.getBorder1());
        map_next_action.setBorder(UBorder.getBorder1());
        map_next_RePun.setBorder(UBorder.getBorder1());
        map_next_mess.setBorder(UBorder.getBorder1());

        map_next_money.setBounds(70,150,150,30);
        map_next_action.setBounds(70,190,150,30);
        map_next_RePun.setBounds(70,230,150,30);
        map_next_mess.setBounds(70,270,150,30);
        map_next_money.setForeground(new Color(58,95,205));
        map_next_RePun.setForeground(new Color(58,95,205));
        map_next_mess.setForeground(new Color(58,95,205));
        map_next_action.setForeground(new Color(58,95,205));
        //导航选择
        map_second_inf.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                inf_panel.remove(map_thread_inf);
                inf_panel.add(map_next_money);
                inf_panel.add(map_next_action);
                inf_panel.add(map_next_RePun);
                inf_panel.add(map_next_mess);
                inf_panel.repaint();
            }
        });
        map_next_money.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                fun_money_panel();
            }
        });
        map_next_action.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                fun_action_panel();
            }
        });
        map_next_RePun.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                fun_RePun_panel();
            }
        });
        map_next_mess.addMouseListener(new MouseAdapter() {
            public void mouseClicked(MouseEvent e) {
                fun_message_panel();
            }
        });
        //菜单选择
        m_money_inf.addActionListener(e -> {
            fun_money_panel();
            map_thread_inf.setText("=>消费记录管理");
            inf_panel.add(map_thread_inf);
        });
        m_action_inf.addActionListener(e -> {
            fun_action_panel();
            map_thread_inf.setText("=>班级活动记录管理");
            inf_panel.add(map_thread_inf);
        });
        m_message_inf.addActionListener(e -> {
            fun_message_panel();
            map_thread_inf.setText("=>班级留言薄管理");
            inf_panel.add(map_thread_inf);
        });
        m_RePun_inf.addActionListener(e -> {
            fun_RePun_panel();
            map_thread_inf.setText("=>班级奖惩记录管理");
            inf_panel.add(map_thread_inf);
        });
    }
    private JTable creatTable(JList<String> list,String[] c_name){
        String[][] str=new String[list.getModel().getSize()][c_name.length];
        for(int i=0;i<list.getModel().getSize();i++) {
            String[] temp= list.getModel().getElementAt(i).split(" , ");
            for(int j=0;j<c_name.length;j++) {
                str[i][j]=temp[j];
            }
        }
        return new JTable(str,c_name);
    }

    void fun_stu_panel(){//郭
        stu_panel = flush();
        JScrollPane scrollPane =new JScrollPane();
        JList<String> list = utable.creat_table_peo("readPeople",className);
        String[] c_name = {"学号","班级","姓名","性别","年龄","联系方式","住址"};
        JTable table = creatTable(list,c_name);
        creatTableSCP(scrollPane,table,stu_panel);
       // creatScoll(scrollPane, list, stu_panel);
        //增加人员
        JButton stu_del = new JButton("删除人员");
        JButton stu_add = new JButton("增加人员");
        JButton stu_update = new JButton("修改人员信息");
        stu_del.setFont(UFONT.getFont4());
        stu_add.setFont(UFONT.getFont4());
        stu_update.setFont(UFONT.getFont4());
        stu_panel.add(stu_add);
        stu_add.setBounds(600,400,150,60);
        stu_add.addActionListener(e -> {
            tf1.setEditable(true);
            JFrame add = new JFrame("信息录入");
            add.setBounds(600,200,400,450);
            add.setLayout(null);
            JButton b_ok = new JButton("确定");
            add.add(b_ok);
            b_ok.setBounds(50,350,100,50);
            set_Stu_Bounds(add);
            //班级下拉框
            JLabel l_class = new JLabel("所属班级");
            l_class.setBounds(30,310,100,50);
            JTextField tf1 = new JTextField(className);
            tf1.setEditable(false);
            tf1.setBounds(100,310,150,40);
            add.add(tf1);
            add.add(l_class);
            b_ok.addActionListener(e1 -> {
            ClassMember classMember= newClassMember(className);
                try {
                    if(db.addClassMember(classMember)){
                        JOptionPane.showMessageDialog(null,"增加成功");
                        add.dispose();
                        BaseWin.remove(stu_panel);
                        BaseWin.repaint();
                        stu_panel.repaint();
                        fun_stu_panel() ;
                    }
                    else {
                        JOptionPane.showMessageDialog(null, "增加失败");
                    }
                } catch (SQLException ex) {
                    JOptionPane.showMessageDialog(null, ex);
                }
            });
            JButton b_cancel = new JButton("取消");
            add.add(b_cancel);
            b_cancel.setBounds(200,350,100,50);
            b_cancel.addActionListener(e1 -> {
                add.dispose();
            });
            add.setResizable(false);
            add.setVisible(true);
        });
        //修改所选人员
        stu_panel.add(stu_update);
        stu_update.setBounds(600,200,150,60);
        int[] flag_id1 = new int[1];
        flag_id1[0]=-1;
        table.getSelectionModel().addListSelectionListener(e1 -> {
            if(table.getSelectedRow()!=-1){
                flag_id1[0]=table.getSelectedRow();
            }
        });
        stu_update.addActionListener(e -> {
            if(flag_id1[0]>=0){
                JFrame update = new JFrame("修改信息");
                update.setBounds(600,210,400,450);
                update.setLayout(null);
                set_Stu_Bounds(update);
                update.setVisible(true);
                JButton b_ok = new JButton("确认");
                update.add(b_ok);
                //班级下拉框
                JLabel l_class = new JLabel("选择所属班级");
                l_class.setBounds(30,310,100,50);
                JTextField tf1 = new JTextField(className);
                tf1.setEditable(false);
                tf1.setBounds(100,310,150,40);
                update.add(tf1);
                update.add(l_class);
                update.setResizable(false);
                tf1.setEditable(false);
                String[] temp= list.getModel().getElementAt(flag_id1[0]).split(" , ");
                tf1.setText(temp[0]);
                tf2.setText(temp[2]);
                tf3.setText(temp[4]);
                tf4.setText(temp[3]);
                tf5.setText(temp[5]);
                tf6.setText(temp[6]);
                b_ok.setBounds(50,350,100,50);
                b_ok.addActionListener(e1 -> {
                    //数据库修改提交请求
                    ClassMember classMember = newClassMember(className);
                    try {
                        if (db.updateClassMember(classMember)){
                            JOptionPane.showMessageDialog(null,"修改成功");
                            update.dispose();
                            BaseWin.remove(stu_panel);
                            BaseWin.repaint();
                            fun_stu_panel();
                        }
                        else JOptionPane.showMessageDialog(null,"修改失败");
                    } catch (SQLException ex) {
                        throw new RuntimeException(ex);
                    }
                });
                JButton b_cancel = new JButton("取消");
                update.add(b_cancel);
                b_cancel.setBounds(200,350,100,50);
                b_cancel.addActionListener(e1 -> {
                    update.dispose();
                });
            }
        });

        //删除所选人员
        stu_panel.add(stu_del);
        stu_del.setBounds(600,300,150,60);
        tf1.setEditable(true);
        stu_del.addActionListener(e -> {
            int[] flag_id = new int[1];
            table.getSelectionModel().addListSelectionListener(e1 -> {
                if(table.getSelectedRow()!=-1){
                    flag_id[0]=table.getSelectedRow();
                    System.out.println(flag_id[0]);
                }
            });
            String[] temp= list.getModel().getElementAt(flag_id1[0]).split(" , ");
            if(0 == JOptionPane.showConfirmDialog(null,"真的要删除选中的人员吗？","删除确认",JOptionPane.YES_NO_OPTION)){
                //删除人员！
                try {
                    if (db.deleteClassMember(temp[0])) {
                        JOptionPane.showMessageDialog(null, "删除成功");
                        BaseWin.remove(stu_panel);
                        BaseWin.repaint();
                        stu_panel.repaint();
                        fun_stu_panel();
                    } else JOptionPane.showMessageDialog(null, "删除失败！");
                } catch (SQLException ex) {
                    JOptionPane.showMessageDialog(null, "删除失败！");
                    System.out.println(ex);
                }
            }
        });
    }

    private ClassMember newClassMember(String string) {//郭
        ClassMember classMember = new ClassMember();
        classMember.setStudentId((int) System.currentTimeMillis());
        classMember.setName(tf2.getText());
        classMember.setClassId(string);
        classMember.setNumber(tf1.getText());
        classMember.setAge(Integer.parseInt(tf3.getText()));
        classMember.setSex(tf4.getText());
        classMember.setContactInfo(tf5.getText());
        classMember.setDormitoryAddress(tf6.getText());
        return classMember;
    }

    private void set_Stu_Bounds(JFrame frame) {//郭
        frame.add(l1);
        l1.setBounds(0,0,50,50);
        frame.add(l2);
        l2.setBounds(0,50,50,50);
        frame.add(l3);
        l3.setBounds(0,100,50,50);
        frame.add(l4);
        l4.setBounds(0,150,50,50);
        frame.add(l5);
        l5.setBounds(0,200,50,50);
        frame.add(l6);
        l6.setBounds(0,250,50,50);
        frame.add(tf1);
        tf1.setBounds(50,0,250,50);
        frame.add(tf2);
        tf2.setBounds(50,50,250,50);
        frame.add(tf3);
        tf3.setBounds(50,100,250,50);
        frame.add(tf4);
        tf4.setBounds(50,150,250,50);
        frame.add(tf5);
        tf5.setBounds(50,200,250,50);
        frame.add(tf6);
        tf6.setBounds(50,250,250,50);
    }
    void fun_unit_panel(){//郭
        unit_panel = flush();
        BaseWin.add(unit_panel);
        unit_panel.setBounds(210,100,800,600);
        JScrollPane scrollPane =new JScrollPane();
        JList<String> list = utable.creat_table_peo("readUnit",className);
        String[] c_name={"学号","班级","姓名","职位","任职日期","暂定任期"};
        JTable table=creatTable(list,c_name);
        creatTableSCP(scrollPane,table,unit_panel);
        JButton b_add = new JButton("增加");
        JButton b_sub = new JButton("删除选中人员");
        b_sub.setFont(UFONT.getFont4());
        b_add.setFont(UFONT.getFont4());
        unit_panel.add(b_add);
        b_add.setBounds(600,400,150,60);
        unit_panel.add(b_sub);
        b_sub.setBounds(600,300,150,60);
        int[] flag_base = new int[1];
        table.getSelectionModel().addListSelectionListener(e2 -> {
            if(table.getSelectedRow()!=-1){
                flag_base[0]=table.getSelectedRow();
            }
        });
        //删除班委会人员
        b_sub.addActionListener(e -> {
            String[] temp = list.getModel().getElementAt(flag_base[0]).split(" , ");
            if (0==JOptionPane.showConfirmDialog(null,"真的要删除吗？","删除确认",JOptionPane.YES_NO_OPTION)) {
                try {
                    if (db.deleteCommitteeStuById(temp[0])) {
                        JOptionPane.showMessageDialog(null, "删除成功");
                        BaseWin.remove(unit_panel);
                        BaseWin.repaint();
                        unit_panel.repaint();
                        scrollPane.repaint();
                        fun_unit_panel();
                    }
                } catch (SQLException ex) {
                    throw new RuntimeException(ex);
                }
            }
        });
        //增加班委会人员
        b_add.addActionListener(e1 -> {
           JFrame frame = new JFrame();
           frame.setLayout(null);
           frame.setResizable(false);
           frame.setBounds(600,200,400,500);
           JScrollPane scp = new JScrollPane();
           JList<String> list1 = utable.creat_table_peo("readPeople",className);
           scrollPane.setBounds(0,0,400,250);
            String[] c_name1 = {"学号","班级","姓名","性别","年龄","联系方式"};
            JTable table1 = creatTable(list1,c_name1);
           scp.getViewport().add(table1,null);
           frame.add(scp);
           scp.setBounds(0,0,400,250);
           frame.setVisible(true);
           JLabel l1 = new JLabel("职位");
           JLabel l2 = new JLabel("日期");
           JLabel l3 =new JLabel("任期");
            JComboBox<String> combo = new JComboBox<>();
            combo.setBounds(150,260,100,30);
            String[] unit_position = db.readUnitPosition();
            for (String string : unit_position) {
                combo.addItem(string);
            }
            frame.add(combo);

           JTextField tf2 = new JTextField("yy-m-d");
           JTextField tf3 = new JTextField();
            frame.add(l1);
            l1.setBounds(0,260,80,40);
            frame.add(l2);
            l2.setBounds(0,310,80,40);
            frame.add(l3);
            l3.setBounds(0,360,80,40);
            //frame.add(tf2);
            //tf2.setBounds(90,310,200,40);
            DatePicker dp = new DatePicker();
            frame.add(dp);
            dp.setBounds(90,310,200,40);
            frame.add(tf3);
            tf3.setBounds(90,360,200,40);
            CommitteeMember committeeMember = new CommitteeMember();
            int[] flag_id = new int[1];
            table1.getSelectionModel().addListSelectionListener(e2 -> {
                if(table1.getSelectedRow()!=-1){
                    flag_id[0]=table1.getSelectedRow();
                }
            });
            JButton b_up =new JButton("提交");
            b_up.setBounds(100,400,100,50);
            frame.add(b_up);
            b_up.addActionListener(e -> {
               if(flag_id[0]>=0){
                   String[] temp= list1.getModel().getElementAt(flag_id[0]).split(" , ");
                   committeeMember.setNumber(temp[0]);
                   committeeMember.setClassName(temp[1]);
                   committeeMember.setStuName(temp[2]);
                   committeeMember.setPosition(Objects.requireNonNull(combo.getSelectedItem()).toString());
                   DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                   try {
                       Date date = dateFormat.parse(DareSelecter.ReDate(dp));
                       committeeMember.setAppointmentDate(date);
                   } catch (ParseException ex) {
                       throw new RuntimeException(ex);
                   }
                   committeeMember.setTermDuration(tf3.getText());
                   try {
                       if(db.addConmmitteeMemeber(committeeMember)) {
                           JOptionPane.showMessageDialog(null, "增添成功");
                           BaseWin.remove(unit_panel);
                           BaseWin.repaint();
                           unit_panel.repaint();
                           scp.repaint();
                           scrollPane.repaint();
                           frame.dispose();
                           fun_unit_panel();
                       } else{
                           JOptionPane.showMessageDialog(null,"增添失败");
                       }
                   } catch (SQLException ex) {
                       throw new RuntimeException(ex);
                   }

               }
           });
        });
    }

    private void creatScoll(JScrollPane scrollPane, JList<String> list, JPanel unitPanel) {
        BaseWin.add(unitPanel);
        unitPanel.setLayout(null);
        unitPanel.setBounds(210,100,800,600);
        BaseWin.repaint();
        unitPanel.add(scrollPane);
        scrollPane.setBounds(0,0,500,500);
        scrollPane.getViewport().add(list,null);
    }

    private void creatTableSCP(JScrollPane scrollPane, JTable table, JPanel unitPanel){
        BaseWin.add(unitPanel);
        unitPanel.setLayout(null);
        unitPanel.setBounds(210,100,800,600);
        BaseWin.repaint();
        unitPanel.add(scrollPane);
        scrollPane.setBounds(0,0,550,500);
        scrollPane.getViewport().add(table,null);
    }

    void fun_duty_panel(){//郭
        duty_panel = flush();
        BaseWin.add(duty_panel);
        duty_panel.setLayout(null);
        duty_panel.setBounds(210,100,800,600);
        BaseWin.repaint();
        JScrollPane jsp = new JScrollPane();
        JList<String> list = utable.creat_table_peo("readDuty",className);
        jsp.getViewport().add(list,null);
        duty_panel.add(jsp);
        String[] c_name = {"学号","班级","姓名","值日日期","值日内容"};
        JTable table = creatTable(list,c_name);
        creatTableSCP(jsp,table,duty_panel);
        //删除
        JButton b_sub = new JButton("删除");
        b_sub.setFont(UFONT.getFont4());
        duty_panel.add(b_sub);
        int[] flag_base = new int[1];
        table.getSelectionModel().addListSelectionListener(e2 -> {
            if(table.getSelectedRow()!=-1){
                flag_base[0]=table.getSelectedRow();
            }
        });
        b_sub.setBounds(600,400,150,60);
        b_sub.addActionListener(e -> {
            if(0==JOptionPane.showConfirmDialog(null,"真的要删除吗？","删除确认",JOptionPane.YES_NO_OPTION)) {
                String[] temp = list.getModel().getElementAt(flag_base[0]).split(" , ");
                try {
                    if (db.deleteDutyById(temp[0])) {
                        JOptionPane.showMessageDialog(null, "删除成功！");
                        BaseWin.remove(duty_panel);
                        BaseWin.repaint();
                        duty_panel.repaint();
                        jsp.repaint();
                        fun_duty_panel();
                    }
                } catch (SQLException ex) {
                    throw new RuntimeException(ex);
                }
            }
        });
        //增加
        JButton b_add = new JButton("增加");
        b_add.setFont(UFONT.getFont4());
        duty_panel.add(b_add);
        b_add.setBounds(600,300,150,60);
        b_add.addActionListener(e -> {
            JFrame frame = new JFrame("值日记录添加");
            frame.setLayout(null);
            frame.setResizable(false);
            frame.setBounds(600,200,400,500);
            JScrollPane scp = new JScrollPane();
            JList<String> list1 = utable.creat_table_peo("readPeople",className);
            String[] c_name1 = {"学号","班级","姓名","性别","年龄","联系方式"};
            JTable table1 = creatTable(list1,c_name1);
            scp.getViewport().add(table1,null);
            frame.add(scp);
            scp.setBounds(0,0,400,250);
            frame.setVisible(true);
            JLabel l1 = new JLabel("值日日期");
            JLabel l2 = new JLabel("值日内容");
            //JTextField tf1 = new JTextField("YY-MM-D");
            JTextField tf2 = new JTextField();
            frame.add(l1);
            l1.setBounds(0,260,80,40);
            frame.add(l2);
            l2.setBounds(0,310,80,40);
            DatePicker dp = new DatePicker();
            frame.add(dp);
            dp.setBounds(90,260,200,40);
            //frame.add(tf1);
            //tf1.setBounds(90,260,200,40);
            frame.add(tf2);
            tf2.setBounds(90,310,200,40);
            int[] flag_id = new int[1];
            table1.getSelectionModel().addListSelectionListener(e2 -> {
                if(table1.getSelectedRow()!=-1){
                    flag_id[0]=table1.getSelectedRow();
                }
            });
            JButton b_up = new JButton("提交");
            frame.add(b_up);
            b_up.setBounds(100,400,100,50);
            b_up.addActionListener(e1 -> {
                if(flag_id[0]>=0){
                    DutySchedule dutySchedule = new DutySchedule();
                    String[] temp=list1.getModel().getElementAt(flag_id[0]).split(" , ");
                    dutySchedule.setNumber(temp[0]);
                    dutySchedule.setClassName(temp[1]);
                    dutySchedule.setStuName(temp[2]);
                    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                    try {
                        Date date = dateFormat.parse(DareSelecter.ReDate(dp));
                        dutySchedule.setDutyDate(date);
                    } catch (ParseException ex) {
                        throw new RuntimeException(ex);
                    }
                    dutySchedule.setTaskDescription(tf2.getText());
                    try {
                        if(db.addDutyStu(dutySchedule)){
                            JOptionPane.showMessageDialog(null,"添加成功");
                            BaseWin.remove(duty_panel);
                            BaseWin.repaint();
                            unit_panel.repaint();
                            frame.dispose();
                            scp.repaint();
                            jsp.repaint();
                            duty_panel.repaint();
                            fun_duty_panel();
                        }
                    } catch (SQLException ex) {
                        throw new RuntimeException(ex);
                    }
                }
            });
        });
    }
    void fun_money_panel(){//王
        money_inf_panel = flush();
        JScrollPane scrollPane =new JScrollPane();
        JList<String> list = utable.creat_table_money("readMoney",className);
        BaseWin.add(money_inf_panel);
        money_inf_panel.setLayout(null);
        money_inf_panel.setBounds(210,100,800,600);
        BaseWin.repaint();
        JButton money_add=new JButton("添加消费记录");
        JButton money_delete=new JButton("删除消费记录");
        String[] c_name={"序号","班级","收入/支出","金额","日期","来源/去向"};
        JTable table = creatTable(list,c_name);
        creatTableSCP(scrollPane,table,money_inf_panel);
        money_inf_panel.add(scrollPane);
        money_inf_panel.add(money_add);
        money_add.setFont(UFONT.getFont4());
        money_add.setBounds(600,400,150,60);
        money_add.addActionListener(e1 -> {
            JFrame frame=new JFrame("录入信息");
            //la1=new JLabel("序号:");
            la2=new JLabel("支出/收入:");
            la3=new JLabel("金额:");
            la4=new JLabel("时间:");
            la5=new JLabel("来源/去向:");
            //ta1=new JTextField();
            ta2=new JTextField();
            JRadioButton b1 = new JRadioButton("收入");
            JRadioButton b2 =new JRadioButton("支出");
            ButtonGroup group = new ButtonGroup();
            group.add(b1);
            group.add(b2);
            DatePicker datePicker = DareSelecter.getDatePicker();
            frame.add(datePicker);
            datePicker.setLocation(120,160);
            ta3=new JTextField();
            //ta4=new JTextField("YY-MM-DD");
            ta5=new JTextField();
            frame.setBounds(600,200,500,450);
            frame.setLayout(null);
            JButton b_ok = new JButton("确定");
            frame.add(b_ok);
            b_ok.setBounds(50,350,100,50);
            set_Money_Bounds(frame,la3,la4,la5,ta3,ta5);
            frame.add(b1);
            frame.add(b2);
            b1.setBounds(100,250,80,60);
            b2.setBounds(200,250,80,60);
            b_ok.addActionListener(e2 -> {
                ExpenseRecord expenseRecord= new ExpenseRecord();
                //expenseRecord.setRecordId(Integer.parseInt(ta1.getText()));
                if (b1.isSelected()){
                    expenseRecord.setExpenseType("收入");
                }
                else if (b2.isSelected()){
                    expenseRecord.setExpenseType("支出");
                }
                expenseRecord.setAmount(BigDecimal.valueOf(Long.parseLong(ta3.getText())));
                expenseRecord.setClassName(className);
                DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                try {
                    Date date = dateFormat.parse(DareSelecter.ReDate(datePicker));
                    expenseRecord.setExpenseDate(date);
                } catch (ParseException ex) {
                    throw new RuntimeException(ex);
                }
                expenseRecord.setRemarks(ta5.getText());
                try {
                    if(db.addExpenseMoney(expenseRecord)){
                        JOptionPane.showMessageDialog(null,"增加成功");
                        frame.dispose();
                        BaseWin.remove(money_inf_panel);
                        BaseWin.repaint();
                        money_inf_panel.repaint();
                        fun_money_panel();
                    }
                    else {
                        JOptionPane.showMessageDialog(null, "增加失败");
                    }
                } catch (SQLException ex) {
                    JOptionPane.showMessageDialog(null, ex);
                }
            });
            JButton b_cancel = new JButton("取消");
            frame.add(b_cancel);
            b_cancel.setBounds(200,350,100,50);
            b_cancel.addActionListener(e3 -> {
                frame.dispose();
            });
            frame.setResizable(false);
            frame.setVisible(true);
        });
        money_inf_panel.add(money_delete);
        money_delete.setFont(UFONT.getFont4());
        money_delete.setBounds(600,300,150,60);
        money_delete.addActionListener(e4 -> {
            int[] flag_id = new int[1];
            table.getSelectionModel().addListSelectionListener(e1 -> {
                if(table.getSelectedRow()!=-1){
                    flag_id[0]=table.getSelectedRow();
                }
            });
            String[] temp= list.getModel().getElementAt(flag_id[0]).split(" , ");
            if(0 == JOptionPane.showConfirmDialog(null,"真的要删除选中的消费记录吗？","删除确认",JOptionPane.YES_NO_OPTION)){
                //删除记录
                try {
                    if(db.deleteMoneyExpense(temp[0])){
                        JOptionPane.showMessageDialog(null,"删除成功");
                        BaseWin.remove(money_inf_panel);
                        BaseWin.repaint();
                        money_inf_panel.repaint();
                        fun_money_panel();
                    }
                    else JOptionPane.showMessageDialog(null,"删除失败！");
                } catch (SQLException ex) {
                    JOptionPane.showMessageDialog(null,"删除失败！");
                }
            }
        });
    }

    private void set_Money_Bounds(JFrame frame,JLabel l3,JLabel l4,JLabel l5,JTextField tf3,JTextField tf5) {
        frame.add(l3);
        l3.setBounds(0,100,100,50);
        frame.add(l4);
        l4.setBounds(0,150,100,50);
        frame.add(l5);
        l5.setBounds(0,200,100,50);
        frame.add(tf3);
        tf3.setBounds(100,100,250,50);

        frame.add(tf5);
        tf5.setBounds(100,200,250,50);
    }
    void fun_action_panel() {//郭
        action_panel=flush();
        JScrollPane scrollPane =new JScrollPane();
        BaseWin.add(action_panel);
        JList<String> list = utable.creat_table_peo("readAction",className);
        String[] c_name = {"序号","班级","活动名称","活动日期","主办方","活动地点","活动人数","活动内容"};
        JTable table =creatTable(list,c_name);
        creatTableSCP(scrollPane,table,action_panel);
        int[] flag_base = new int[1];
        table.getSelectionModel().addListSelectionListener(e2 -> {
            if(table.getSelectedRow()!=-1){
                flag_base[0]=table.getSelectedRow();
            }
        });
        //移除所选活动
        JButton action_sub  = new JButton("移除");
        action_sub.setFont(UFONT.getFont4());
        action_panel.add(action_sub);
        action_sub.setBounds(600,400,150,60);
        action_sub.addActionListener(e3 -> {
            if(0==JOptionPane.showConfirmDialog(null,"真的要删除吗？","删除确认",JOptionPane.YES_NO_OPTION)){
                String[] temp= list.getModel().getElementAt(flag_base[0]).split(" , ");
                if(flag_base[0]>=0) {
                    try {
                        if (db.deleteActivityById(Integer.valueOf(temp[0]))) {
                            JOptionPane.showMessageDialog(null, "删除成功！");
                            BaseWin.remove(action_panel);
                            action_panel.removeAll();
                            action_panel.repaint();
                            BaseWin.repaint();
                            fun_action_panel();
                        }
                    } catch (SQLException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        });
        //增加活动
        JButton action_add = new JButton("增加");
        action_add.setFont(UFONT.getFont4());
        action_panel.add(action_add);
        action_add.setBounds(600,300,150,60);
        action_add.addActionListener(e1 -> {
            JFrame frame =new JFrame("增加活动记录");
            frame.setBounds(500,200,325,500);
            frame.setResizable(false);
            JLabel l1 =new JLabel("序号");
            JLabel l2 =new JLabel("活动名称");
            JLabel l3 =new JLabel("活动日期");
            JLabel l4 =new JLabel("主办人");
            JLabel l5 =new JLabel("地点");
            JLabel l6 =new JLabel("活动人数");
            JLabel l7 =new JLabel("活动内容");
            JTextField tf1 =new JTextField();
            JTextField tf2 =new JTextField();
            //JTextField tf3 =new JTextField("YY-MM-DD");
            JTextField tf4 =new JTextField();
            JTextField tf5 =new JTextField();
            JTextField tf6 =new JTextField();
            JTextField tf7 =new JTextField();
            l2.setBounds(0,50,100,50);
            l3.setBounds(0,100,100,50);
            frame.add(l2);
            l4.setBounds(0,150,100,50);
            l5.setBounds(0,200,100,50);
            frame.add(l3);
            frame.add(l4);
            l6.setBounds(0,250,100,50);
            frame.add(l5);
            frame.add(l6);
            l7.setBounds(0,300,100,50);
            frame.add(l7);
            //frame.add(tf1);
            frame.add(tf2);
            //tf1.setBounds(110,0,190,50);
            tf2.setBounds(110,50,190,50);
            DatePicker dp = new DatePicker();
            frame.add(dp);
            dp.setBounds(110,105,180,40);
            //frame.add(tf3);
            //tf3.setBounds(110,100,190,50);
            frame.add(tf4);
            tf4.setBounds(110,150,190,50);
            frame.add(tf5);
            tf5.setBounds(110,200,190,50);
            frame.add(tf6);
            tf6.setBounds(110,250,190,50);
            frame.add(tf7);
            tf7.setBounds(110,300,190,50);
            JButton b_up =new JButton("提交");
            frame.add(b_up);
            frame.setLayout(null);
            b_up.setBounds(100,400,100,50);
            frame.setVisible(true);
            b_up.addActionListener(e2 -> {
                ActivityRecord action = new ActivityRecord();
                //action.setActivityId(Integer.parseInt(tf1.getText()));
                action.setActivityName(tf2.getText());
                DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                try {
                    Date date = dateFormat.parse(DareSelecter.ReDate(dp));
                    action.setActivityDate(date);
                } catch (ParseException ex) {
                    throw new RuntimeException(ex);
                }
                action.setHost(tf4.getText());
                action.setClassName(className);
                action.setLocation(tf5.getText());
                action.setParticipantsCount(Integer.parseInt(tf6.getText()));
                action.setActivityContent(tf7.getText());
                try {
                    if (db.addActivity(action)){
                        JOptionPane.showMessageDialog(null,"增添成功");
                        BaseWin.remove(action_panel);
                        action_panel.removeAll();
                        BaseWin.repaint();
                        frame.dispose();
                        fun_action_panel();
                    }
                } catch (SQLException e) {
                    throw new RuntimeException(e);
                }
            });
        });
    }
    private NewManPanel flush(){//郭
        BaseWin.remove(stu_panel);
        BaseWin.remove(unit_panel);
        BaseWin.remove(duty_panel);
        BaseWin.remove(money_inf_panel);
        BaseWin.remove(action_panel);
        BaseWin.remove(message_panel);
        BaseWin.remove(RePun_panel);
        RePun_panel.removeAll();
        stu_panel.removeAll();
        unit_panel.removeAll();
        duty_panel.removeAll();
        money_inf_panel.removeAll();
        action_panel.removeAll();
        message_panel.removeAll();
        return new NewManPanel();
    }
    void fun_message_panel(){//王
        BaseWin.remove(message_panel);
        message_panel = new JPanel();
        message_panel=flush();
        JScrollPane scrollPane =new JScrollPane();
        JList<String> list = utable.creat_table_message("readMessage",className);
        BaseWin.add(message_panel);
        message_panel.setLayout(null);
        message_panel.setBounds(210,100,800,600);
        BaseWin.repaint();
        String[] c_name = {"序号","班级","姓名","留言内容","留言时间"};
        JTable table = creatTable(list,c_name);
        creatTableSCP(scrollPane,table,message_panel);
        message_panel.add(scrollPane);
        scrollPane.setBounds(0,0,550,500);
        JButton message_add=new JButton("添加留言");
        JButton message_delete=new JButton("删除留言");
        message_delete.setFont(UFONT.getFont4());
        message_add.setFont(UFONT.getFont4());
        //增加记录留言
        message_panel.add(message_add);
        message_add.setBounds(600,400,150,60);
        int[] flag_id = new int[1];
        table.getSelectionModel().addListSelectionListener(e1 -> {
            if(table.getSelectedRow()!=-1){
                flag_id[0]=table.getSelectedRow();
            }
        });
        message_add.addActionListener(e -> {
            JFrame frame = new JFrame("录入留言");
            //la1=new JLabel("序号:");
            //la2=new JLabel("学号:");
            la3=new JLabel("姓名:");
            la4=new JLabel("留言内容:");
            la5=new JLabel("留言时间:");
            //ta1=new JTextField();
            //ta2=new JTextField();
            ta3=new JTextField();
            ta4=new JTextField();
            //ta5=new JTextField();
            frame.setBounds(600,200,400,450);
            frame.setLayout(null);
            JButton b_ok = new JButton("确定");
            frame.add(b_ok);
            b_ok.setBounds(50,350,100,50);
            set_Message_Bounds(frame,la3,la4,la5,ta3,ta4);
            DatePicker dp = new DatePicker();
            frame.add(dp);
            dp.setBounds(50,200,250,50);
            b_ok.addActionListener(e1 -> {
                MessageBoard messageBoard= new MessageBoard();
                //messageBoard.setMessageId(Integer.parseInt(ta1.getText()));
                //messageBoard.setStudentId(Integer.parseInt(ta2.getText()));
                messageBoard.setStudentName(ta3.getText());
                messageBoard.setMessageContent(ta4.getText());
                messageBoard.setMessageDate(DareSelecter.ReDate(dp));
                messageBoard.setClassName(className);

                try {
                    if(db.addMessageBoard(messageBoard)){
                        JOptionPane.showMessageDialog(null,"增加成功");
                        frame.dispose();
                        BaseWin.remove(message_panel);
                        BaseWin.repaint();
                        message_panel.repaint();
                        fun_message_panel();
                    }
                    else {
                        JOptionPane.showMessageDialog(null, "增加失败");
                    }
                } catch (SQLException ex) {
                    JOptionPane.showMessageDialog(null, ex);
                }
            });
            JButton b_cancel = new JButton("取消");
            frame.add(b_cancel);
            b_cancel.setBounds(200,350,100,50);
            b_cancel.addActionListener(e3 -> {
                frame.dispose();
            });
            frame.setResizable(false);
            frame.setVisible(true);
        });
        //删除记录
        message_panel.add(message_delete);
        message_delete.setBounds(600,300,150,60);
        message_delete.addActionListener(e4 -> {

            String[] temp= list.getModel().getElementAt(flag_id[0]).split(" , ");
            if(0 == JOptionPane.showConfirmDialog(null,"真的要删除选中的人员吗？","删除确认",JOptionPane.YES_NO_OPTION)){
                //删除人员！
                try {
                    if(db.deleteMessageBoard(temp[0])){
                        JOptionPane.showMessageDialog(null,"删除成功");
                        BaseWin.remove(message_panel);
                        BaseWin.repaint();
                        message_panel.repaint();
                        fun_message_panel();
                    }
                    else JOptionPane.showMessageDialog(null,"删除失败！");
                } catch (SQLException ex) {
                    JOptionPane.showMessageDialog(null,"删除失败！");
                }
            }
        });
    }
    private void set_Message_Bounds(JFrame frame,JLabel l3,JLabel l4,JLabel l5,JTextField tf3,JTextField tf4) {
        frame.add(l3);
        l3.setBounds(0,100,50,50);
        frame.add(l4);
        l4.setBounds(0,150,50,50);
        frame.add(l5);
        l5.setBounds(0,200,50,50);
        frame.add(tf3);
        tf3.setBounds(50,100,250,50);
        frame.add(tf4);
        tf4.setBounds(50,150,250,50);
    }
    void fun_RePun_panel(){//郭
        BaseWin.remove(RePun_panel);
        RePun_panel = flush();
        JScrollPane scrollPane =new JScrollPane();
        JList<String> list = utable.creat_table_peo("readRePun", className);
        BaseWin.add(RePun_panel);
        RePun_panel.setLayout(null);
        RePun_panel.setBounds(210,100,800,600);
        BaseWin.repaint();
        String[] c_name={"序号","学号","姓名","处分/奖励","理由","日期"};
        JTable table = creatTable(list,c_name);
        creatTableSCP(scrollPane,table,RePun_panel);
        JButton RePun_add=new JButton("增加记录");
        JButton RePun_delete=new JButton("删除记录");
        RePun_delete.setFont(UFONT.getFont4());
        RePun_add.setFont(UFONT.getFont4());
        RePun_panel.add(scrollPane);
        //增加奖惩记录
        RePun_panel.add(RePun_add);
        RePun_add.setBounds(600,400,150,60);
        RePun_add.addActionListener(e -> {
            JFrame frame = new JFrame("奖惩记录添加");
            frame.setLayout(null);
            frame.setResizable(false);
            frame.setBounds(600,200,400,500);
            JScrollPane scp = new JScrollPane();
            JList<String> list1 = utable.creat_table_peo("readPeople",className);
            String[] c_name1 = {"学号","姓名","性别","年龄","联系方式"};
            JTable table1 = creatTable(list1,c_name1);
            scp.getViewport().add(table1,null);
            frame.add(scp);
            scp.setBounds(0,0,400,250);
            frame.setVisible(true);
            //JLabel l1 = new JLabel("奖惩类型");
            JLabel l2 = new JLabel("理由");
            JLabel l3 =new JLabel("日期");
            //JTextField tf1 = new JTextField();
            JTextField tf3 = new JTextField("YY-MM-D");
            JTextField tf2 = new JTextField();
            //frame.add(l1);
            //l1.setBounds(0,260,80,40);
            ButtonGroup group = new ButtonGroup();
            JRadioButton r1=new JRadioButton("奖励");
            JRadioButton r2=new JRadioButton("处分");
            group.add(r1);
            group.add(r2);
            frame.add(r1);
            frame.add(r2);
            r1.setBounds(100,260,80,40);
            r2.setBounds(200,260,80,40);
            frame.add(l2);
            l2.setBounds(0,310,80,40);
            frame.add(l3);
            l3.setBounds(0,370,80,40);
            //frame.add(tf1);
            //tf1.setBounds(90,260,200,40);
            frame.add(tf2);
            tf2.setBounds(90,310,200,40);
            DatePicker dp =new DatePicker();
            frame.add(dp);
            dp.setBounds(90,370,180,40);
            //frame.add(tf3);
            //tf3.setBounds(90,370,200,40);
            int[] flag_id = new int[1];
            table1.getSelectionModel().addListSelectionListener(e2 -> {
                if(table1.getSelectedRow()!=-1){
                    flag_id[0]=table1.getSelectedRow();
                    System.out.println(flag_id[0]);
                }
            });
            JButton b_up = new JButton("提交");
            frame.add(b_up);
            b_up.setBounds(100,410,100,50);
            b_up.addActionListener(e1 -> {
               if(flag_id[0]>=0){
                   String[] temp= list1.getModel().getElementAt(flag_id[0]).split(" , ");
                   RewardPunishmentRecord reward=new RewardPunishmentRecord();
                   reward.setNumber(temp[0]);
                   if (r1.isSelected()){
                       reward.setRpType("奖励");
                   }
                  else if (r2.isSelected()){
                      reward.setRpType("处分");
                   }
                   reward.setReason(tf2.getText());
                   reward.setClassName(className);
                   DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
                   try {
                       Date date = dateFormat.parse(DareSelecter.ReDate(dp));
                       reward.setRpDate(date);
                   } catch (ParseException ex) {
                       throw new RuntimeException(ex);
                   }
                   if (db.addRewardPun(reward)){
                       JOptionPane.showMessageDialog(null,"增添成功");
                       BaseWin.remove(RePun_panel);
                       BaseWin.repaint();
                       frame.dispose();
                       fun_RePun_panel();
                   }
               }
            });
        });
        int[] flag_id = new int[1];
        table.getSelectionModel().addListSelectionListener(e1 -> {
            if(table.getSelectedRow()!=-1){
                flag_id[0]=table.getSelectedRow();
                System.out.println(flag_id[0]);
            }
        });
        RePun_panel.add(RePun_delete);
        RePun_delete.setBounds(600,300,150,60);
        RePun_delete.addActionListener(e4 -> {

            String[] temp= list.getModel().getElementAt(flag_id[0]).split(" , ");
            if(0 == JOptionPane.showConfirmDialog(null,"真的要删除选中的信息？","删除确认",JOptionPane.YES_NO_OPTION)){
                //删除奖惩记录
                try {
                    if(db.deleteRePun(Integer.parseInt(temp[0]))){
                        JOptionPane.showMessageDialog(null,"删除成功");
                        BaseWin.remove(RePun_panel);
                        BaseWin.repaint();
                        RePun_panel.repaint();
                        fun_RePun_panel();
                    }
                    else JOptionPane.showMessageDialog(null,"删除失败！");
                } catch (SQLException ex) {
                    JOptionPane.showMessageDialog(null,"删除失败！");
                }
            }
        });
        //查询奖惩记录
        JButton b_find = new JButton("查询记录");
        RePun_panel.add(b_find);
        b_find.setFont(UFONT.getFont4());
        b_find.setBounds(600,200,150,60);
        b_find.addActionListener(e->{
            JFrame frame = new JFrame("奖惩记录查询");
            frame.setLayout(null);
            frame.setResizable(false);
            frame.setBounds(600,200,430,500);
            JTextField tf = new JTextField();
            frame.add(tf);
            tf.setBounds(80,300,200,40);
            JLabel j1 = new JLabel("查询学号");
            frame.add(j1);
            j1.setBounds(15,300,70,40);
            JButton b_up =new JButton("查询");
            frame.add(b_up);
            b_up.setBounds(120,400,100,40);
            b_up.addActionListener(e1 -> {
                JScrollPane scp = new JScrollPane();
                String num = tf.getText();
                if (num.isEmpty()){
                    JOptionPane.showMessageDialog(null,"请输入查询学号");
                }
                else{
                    JList<String> list1 = utable.creat_table_peo("readRePun_findNum",num);
                    String[] c_name1 = {"序号","学号","姓名","处分/奖励","理由","日期"};
                    JTable table1 = creatTable(list1,c_name1);
                    scp.getViewport().add(table1,null);
                    frame.add(scp);
                    scp.setBounds(0,0,400,250);
                }
            });
            frame.setVisible(true);
        });
    }


}
